import Vue from 'vue';
import axios from "axios";
import Router from 'vue-router';
import Login from '@/page/login';
import Index from '@/page/index';
import User from '@/page/user';
import Role from '@/page/role';
import Grant from '@/page/grant';
import Log from '@/page/log';
import Dictionary from '@/page/dictionary';
import System from '@/page/system';

Vue.use(Router);

export default new Router({
  linkActiveClass:'on',//设置 链接激活时使用的 CSS 类名。默认值可以通过路由的构造选项 linkActiveClass 来全局配置。
  routes: [
    {
      path: '/',
      name: 'login',
      meta:{
        tabbar: false,
      },
      component: Login
    },
    {
      path: '/index',
      name: 'index',
      meta:{
        tabbar: true,
      },
      component: Index
    },
    {
      path: '/user',
      name: 'user',
      meta:{
        tabbar: true,
      },
      component: User
    },
    {
      path: '/role',
      name: 'role',
      meta:{
        tabbar: true,
      },
      component: Role
    },
    {
      path: '/grant',
      name: 'grant',
      meta:{
        tabbar: true,
      },
      component: Grant
    },
    {
      path: '/log',
      name: 'log',
      meta:{
        tabbar: true,
      },
      component: Log
    },
    {
      path: '/dictionary',
      name: 'dictionary',
      meta:{
        tabbar: true,
      },
      component: Dictionary
    },
    {
      path: '/system',
      name: 'system',
      meta:{
        tabbar: true,
      },
      component: System
    },
  ]
})

// http请求拦截器
axios.interceptors.request.use(
  config => {
    // 在发送请求之前做些什么
    let timestamp2=new Date().getTime();
    let timeCha = timestamp2-appDB.get("timeOut");
    // console.info(timeCha)
    if(timeCha<10800000){
        appDB.set("timeOut",timestamp2)
    }else{
      this.a.push("/")//如果俩次请求时间超过3小时则要求从新登录
      // layer.msg("操作超时，请从新登录！")
    }
    return config;
  },
  error => {
    // 对请求错误做些什么
    return Promise.reject(error);
  }
);
